package interview.data_structure;

/**
 * @author fance
 * @date 2018/7/14 15:42
 */
class NodeII<E> {
    NodeII next;
    E data;

    public NodeII(E data) {
        this.data = data;
    }
}

public class MyStackUseList<E> {
    NodeII<E> top = null;
    public boolean isEmpty() {
        return top == null;
    }

    public void push(E data) {
        NodeII<E> newNode = new NodeII<>(data);
        newNode.next = top;
        top = newNode;
    }

    public E pop() {
        if (isEmpty()) {
            return null;
        }
        E data = top.data;
        top = top.next;
        return data;
    }
    public E peek() {
        return isEmpty() ? null : top.data;
    }
}